package org.ymjava.medical.db.AllPackage.biz;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.ymjava.medical.db.AbstractBaseBiz.BaseBiz;
import org.ymjava.medical.db.AllPackage.entity.SysPerm;
import org.ymjava.medical.db.AllPackage.mapper.SysPermMapper;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 权限表
 *
 * @author zhy
 * @email ${email}
 * @date 2020-04-03 15:53:44
 */
@Service
public class SysPermBiz extends BaseBiz<SysPermMapper,SysPerm> {

	@Resource
	private SysPermMapper sysPermMapper;

	public List<Map> getPermsByUserId(Integer userId){
		return sysPermMapper.getPermsByUserId(userId);
	}

	public List<SysPerm> getPermsByRoleId(Integer roleId){
		return sysPermMapper.getPermsByRoleId(roleId);
	}

	public List<SysPerm> getList(Integer ptype){
		Example example = new Example(SysPerm.class);
		if(!StringUtils.isEmpty(ptype)){
			example.createCriteria().andEqualTo("ptype",ptype);
		}
		return sysPermMapper.selectByExample(example);
	}

	public void deleteByptype(Integer ptype){
		SysPerm sysPerm = new SysPerm();
		sysPerm.setPtype(ptype);
		sysPermMapper.delete(sysPerm);
	}

	public void saveOrUpdate(List<SysPerm> perms){
		if (perms!=null&&!perms.isEmpty()){
			sysPermMapper.saveOrUpdate(perms);
		}
	}
}